package xju.ssm_11_12.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import xju.ssm_11_12.entity.User;
import xju.ssm_11_12.service.UserService;

import java.util.List;

@Controller
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping
    @ResponseBody
    public List<User> index() {
        List<User> list =  userService.selectAll();
        return list;
    }

    @GetMapping("/{id}")
    @ResponseBody
    public User show(@PathVariable int id) {
       User user =  userService.selectById(id);
       return user;
    }
}
